package com.frinder.seata.order.service;

import com.frinder.seata.data.base.Result;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @ClassName CallStorageFallbackFactory
 * @Description 库存服务熔断机制
 * @Author frinder
 * @Date 2020/8/18 15:53
 * @Verion 1.0
 */
@Slf4j
@Component
public class CallStorageFallbackFactory implements FallbackFactory<CallStorageService> {
    @Override
    public CallStorageService create(Throwable e) {
        return (productId, qty) -> {
            log.error("扣减库存服务熔断生效，商品[{}]，扣减数量[{}]，失败原因[{}]",
                    productId, qty, e.getMessage());
            return Result.selfFail(e.getMessage());
        };
    }
}
